<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="24">
                <el-card shadow="hover" class="mgb20" style="height:100%;">
                    <div class="user-info">
                        <img src="../../assets/img/mm.jpg" class="user-avator" alt />
                        <div class="user-info-cont">
                            <div class="user-info-name">欢迎您,{{name}}</div>
                            <div>{{role}}</div>
                        </div>
                    </div>
                    <!--<div class="user-info-list">
                        上次登录时间：
                        <span>2019-11-01</span>
                    </div>
                    <div class="user-info-list">
                        上次登录地点：
                        <span>东莞</span>
                    </div>-->
                    <div class="crumbs">
			            <el-breadcrumb separator="/">
			                <el-breadcrumb-item>
			                    <i class="el-icon-pie-chart"></i> 统计图表
			                </el-breadcrumb-item>
			            </el-breadcrumb>
			        </div>
			        <div class="container">
			           
			            <div class="schart-box">
			                <div class="content-title">最近7天收集资料情况</div>
			                <schart class="schart" canvasId="bar" :options="options1"></schart>
			            </div>
			           <!-- <div class="schart-box">
			                <div class="content-title">折线图</div>
			                <schart class="schart" canvasId="line" :options="options2"></schart>
			            </div>-->
			            <div class="schart-box">
			                <div class="content-title">部门人数分布图</div>
			                <schart class="schart" canvasId="pie" :options="options3"></schart>
			            </div>
			            <div class="schart-box">
			                <div class="content-title">用 户角色分布图</div>
			                <schart class="schart" canvasId="ring" :options="options4"></schart>
			            </div>
			        </div>
                </el-card>
            </el-col>
        </el-row>
		
    </div>
</template>

<script>
import Schart from 'vue-schart';
import bus from '../common/bus';
export default {
    name: 'dashboard',
    data() {
        return {
            name: localStorage.getItem('ms_username'),
            level: sessionStorage.getItem('level'),
            options1: {
                type: 'bar',
                title: {
                    text: '最近7天收集资料情况'
                },
                bgColor: '#fbfbfb',
                labels: [],
                datasets: [
                    {
                        label: '',
                        //fillColor: 'rgba(241, 49, 74, 0.5)',
                        data: []
                    }
                ]
            },
            options3: {
                type: 'pie',
                title: {
                    text: '部门人数分布图'
                },
                legend: {
                    position: 'left'
                },
                bgColor: '#fbfbfb',
                labels: ['主席团', '宣传部', '外联部', '办公室', '自律部', '文体部', '组织部'],
                datasets: [
                    {
                        data: [4, 10, 8, 12, 9, 10, 10]
                    }
                ]
            },
            options4: {
                type: 'ring',
                title: {
                    text: '用户角色分布图'
                },
                //showValue: false,
                legend: {
                    position: 'bottom',
                    bottom: 40
                },
                bgColor: '#fbfbfb',
                labels: ['辅导员', '团学干部', '班级负责人'],
                datasets: [
                    {
                        data: [2, 50, 30]
                    }
                ]
            }
        };
    },
    components: {
    	Schart
    },
    created() {
    	this.getMaterialsData();
    	this.getLeagueCadresData();
    	this.getRolesData();
    	this.getTotalNotCommitMaterial();
    },
    computed: {
    	
        role() {
            return this.level === '1' ? '角色：系统管理员' : this.level === '2'? '角色：辅导员' : this.level === '3'? '角色：学生会主席'  :  this.level === '4'? '角色：学生会部长'  :  this.level === '5'? '角色：干事': this.level === '6'? '角色：班级负责人'  : '角色：普通用户';
        }
    },
    methods: {
    	// 统计最近7天收集资料情况
    	async getMaterialsData(){
    		let _this = this;
	        let res = await _this.$Http.totalMaterialsBefore7days(
	        	{
	        	},
                true
	        );
	       	console.log(res.data);
	        if (res.status==0){
		        this.options1.labels = res.data.dateRange;
		        if(res.data.totalCount > 0){
		        	this.options1.datasets = res.data.dataSet;
		        }
	        }else{
	        	 this.$message.success(res.msg);
	        }
	        
	        
    	},
    	//统计各部门人数
    	async getLeagueCadresData(){
	    	
	    	let _this = this;
	        let res = await _this.$Http.totalLeagueCadres(
	        	{
	        		
	        	},
                true
	        );
	        
	        /*console.log(res.data);
			console.log("orgNames[]=",res.data.orgNames);
			console.log("orgCount[]=",res.data.orgCount);*/
	        this.options3.labels = res.data.orgNames;
	        this.options3.datasets[0].data = res.data.orgCount;

	    },
	    //用户角色分布
	    async getRolesData(){
	    	let _this = this;
	        let res = await _this.$Http.totalRoles(
	        	{
	        	},
                true
	        );
	        
	        /*console.log(res.data);
			console.log("roleNames[]=",res.data.roleNames);
			console.log("roleCount[]=",res.data.roleCount);*/
	        this.options4.labels = res.data.roleNames;
	        this.options4.datasets[0].data = res.data.roleCount;
	    },
        changeDate() {
            const now = new Date().getTime();
            this.data.forEach((item, index) => {
                const date = new Date(now - (6 - index) * 86400000);
                item.name = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
            });
        },
        async getTotalNotCommitMaterial(){
        	let _this = this;
	        let res = await _this.$Http.getTotalNotCommitMaterialForClass(
	        	{
	        	},
                true
	        );
	        
	        console.log(res);
	        
	        if (res.status=="0"){
	        	if (res.data.totalCount > 0){
	        		console.log("res.data.tempList=",res.data.tempList)
	        		let list = res.data.tempList;
	        		for(let item in list){
	        			console.log("temp=",list[item])
	        			let temp = list[item];
	        			setTimeout(()=>{
                		this.$notify({
				          title: '提示',
				          message: '您有资料尚未提交,请及时提交。'+'模板ID:'+temp.tempId+',模板主题:'+temp.templateTheme+',截至时间:'+temp.endDate,
				          position: 'bottom-right',
				          duration: 0
				        });
            			},1000);
	        			
	        		}
	        		
	        	}
	        }
        }
    }
};
</script>


<style scoped>
.el-row {
    margin-bottom: 20px;
}

.grid-content {
    display: flex;
    align-items: center;
    height: 100px;
}

.grid-cont-right {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: #999;
}

.grid-num {
    font-size: 30px;
    font-weight: bold;
}

.grid-con-icon {
    font-size: 50px;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    color: #fff;
}

.grid-con-1 .grid-con-icon {
    background: rgb(45, 140, 240);
}

.grid-con-1 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-2 .grid-con-icon {
    background: rgb(100, 213, 114);
}

.grid-con-2 .grid-num {
    color: rgb(45, 140, 240);
}

.grid-con-3 .grid-con-icon {
    background: rgb(242, 94, 67);
}

.grid-con-3 .grid-num {
    color: rgb(242, 94, 67);
}

.user-info {
    display: flex;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #ccc;
    margin-bottom: 20px;
}

.user-avator {
    width: 120px;
    height: 120px;
    border-radius: 50%;
}

.user-info-cont {
    padding-left: 50px;
    flex: 1;
    font-size: 14px;
    color: #999;
}

.user-info-cont div:first-child {
    font-size: 30px;
    color: #222;
}

.user-info-list {
    font-size: 14px;
    color: #999;
    line-height: 25px;
}

.user-info-list span {
    margin-left: 70px;
}

.mgb20 {
    margin-bottom: 20px;
}

.todo-item {
    font-size: 14px;
}

.todo-item-del {
    text-decoration: line-through;
    color: #999;
}

.schart {
    width: 100%;
    height: 300px;
}

</style>
